package com.IOSLab.service.Impl;

import com.IOSLab.common.ServerResponse;
import com.IOSLab.dao.UserInfoMapper;
import com.IOSLab.dto.UserInfoExecution;
import com.IOSLab.entity.UserInfo;
import com.IOSLab.enums.UserInfoEnum;
import com.IOSLab.service.IUserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service("iUserInfoService")
public class UserInfoServiceImpl implements IUserInfoService {

    @Autowired
    private UserInfoMapper userInfoMapper;

    @Override
    public UserInfoExecution Login(String username, String password) {
        int resultCount = userInfoMapper.checkStudentId(username);
        if (resultCount == 0) {
            return new UserInfoExecution(UserInfoEnum.INNER_ERROR);
        }
        // todo 密码md5
        String Md5password="s";
        UserInfo userInfo = userInfoMapper.selectLogin(username, password);
        if (userInfo == null) {
            return new UserInfoExecution(UserInfoEnum.INNER_ERROR);
        }

        return new UserInfoExecution(UserInfoEnum.SUCCESS);
    }

    @Override
    public UserInfoExecution Register(UserInfo userInfo) {
        int resultCount = userInfoMapper.checkStudentId(userInfo.getStudentId());
        if (resultCount > 0) {
            return new UserInfoExecution(UserInfoEnum.INNER_ERROR);
        }
        resultCount=userInfoMapper.insert(userInfo);
        if(resultCount==0){
            return new UserInfoExecution(UserInfoEnum.INNER_ERROR);
        }
        else
        return new UserInfoExecution(UserInfoEnum.SUCCESS);

    }


}
